import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer, TfidfTransformer
from sklearn.model_selection import train_test_split
df = pd.read_csv("../datas/bayes_wenben.txt", header=None)
X = df[1]
Y = df[0]
# print(Y)
tfCoder = TfidfVectorizer(token_pattern="[a-zA-Z|\u4e00-\u9fa5]+")
X = tfCoder.fit_transform(X)
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.5)

from sklearn.naive_bayes import MultinomialNB
model = MultinomialNB()
model.fit(X_train,y_train)
print(y_test.shape[0])
# 准确率
print(sum(model.predict(X_test)==y_test.values)/y_test.shape[0])
